#!/bin/bash
set -eo pipefail
source /etc/profile
env="{{ var.value.env | lower }}"
dt='{{ execution_date | cst_ds }}'
defaultFS=''
endpoint=''
index=''
alias=''
if [ ${env} == "test" ];
then
  status=`hdfs haadmin -getServiceState nn1` || echo "standby"
  echo ${status}
  if [ "${status}" == "active" ]; then
      defaultFS="hdfs://192.168.12.136:8020"
  else
    defaultFS="hdfs://192.168.12.137:8020"
  fi
    endpoint="http://192.168.12.201:9200"
  index="test_address_library_new"
  alias="test_address_library_search"
#elif [ ${env} == "pro" ];
#then
#  status=`hdfs haadmin -getServiceState nn1` || echo "standby"
#  echo ${status}
#  if [ "${status}" == "active" ]; then
#      defaultFS="hdfs://10.33.48.4:8020"
#  else
#      defaultFS="hdfs://10.33.48.5:8020"
#  fi
#    endpoint="http://192.168.12.201:9200"
#  index="test_address_library_new"
#  alias="test_address_library_search"
#else
#  echo "env参数不正确"
elif [ ${env} == "pro" ];
then
  status=`hdfs haadmin -getServiceState nn1` || echo "standby"
  echo ${status}
  if [ "${status}" == "active" ]; then
      defaultFS="hdfs://10.33.48.4:8020"
  else
      defaultFS="hdfs://10.33.48.5:8020"
  fi
  endpoint="http://10.33.40.71:9200/"
  index="pro_address_library_new"
  alias="pro_address_library_search"
else
  echo "env参数不正确"
fi
  python /opt/datax/bin/datax.py -p "-Dalias=${alias} -Dindex=${index} -DdefaultFS=${defaultFS} -Dendpoint=${endpoint} -Ddt=${dt}" hdfs2es_cn_address_warehouse_day_rule.json
